package com.hwd.srb.core.controller.admin;


import com.hwd.srb.common.result.R;
import com.hwd.srb.core.pojo.entity.Lend;
import com.hwd.srb.core.service.LendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author 黄伟东/Victor
 * @since 2022-03-10
 */
@RestController
@RequestMapping("/admin/core/lend")
@Api(tags = "标的管理")
public class AdminLendController {

    @Resource
    private LendService lendService;

    /**
     * 放款
     *
     * @param lendId 标的id
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("放款")
    @GetMapping("/makeLoan/{id}")
    public R makeLoan(@ApiParam(value = "标的id", required = true, example = "1")
                      @PathVariable("id") Long lendId) {

        lendService.makeLoan(lendId);

        return R.ok().message("放款成功");
    }

    /**
     * 查询标的列表
     *
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("标的列表")
    @GetMapping("/list")
    public R list() {
        List<Lend> lendList = lendService.selectList();
        return R.ok().data("list", lendList);
    }

    /**
     * 根据标的id获取标的信息
     *
     * @param lendId 标的id
     * @return com.hwd.srb.common.result.R
     */
    @ApiOperation("获取标的信息")
    @GetMapping("/show/{id}")
    public R show(
            @ApiParam(value = "标的id", required = true, example = "1")
            @PathVariable("id") Long lendId) {

        Map<String, Object> result = lendService.getLendDetail(lendId);

        return R.ok().data("lendDetail", result);
    }
}

